package com.googlecode.jcompilo;

import com.googlecode.totallylazy.Block;
import com.googlecode.totallylazy.Bytes;
import com.googlecode.totallylazy.Function1;
import com.googlecode.totallylazy.Mapper;
import com.googlecode.totallylazy.Runnables;

import java.io.InputStream;
import java.io.Writer;
import java.util.Properties;

public class MoveToTL {
    public static Mapper<InputStream, byte[]> read() {
        return new Mapper<InputStream, byte[]>() {
            @Override
            public byte[] call(InputStream inputStream) throws Exception {
                return Bytes.bytes(inputStream);
            }
        };
    }

    public static String classNameForSource(String sourceFilename) {
        return sourceFilename.replace(".java", "").replace('/', '.');
    }

    public static String classNameForByteCode(String sourceFilename) {
        return sourceFilename.replace(".class", "").replace('/', '.');
    }

    public static String classFilename(String className) {
        return className.replace('.', '/') + ".class";
    }

    public static Block<Writer> write(final Properties properties) {
        return new Block<Writer>() {
            @Override
            protected void execute(Writer writer) throws Exception {
                properties.store(writer, "");
            }
        };
    }
}
